<?php 
include_once '../Utilities/connect.php';
$conn=  getConnect();
mysql_set_charset('utf8',$conn);
/* @var $conn type */


function getByCategory($categoryId, $start, $display)
{
 		$sql= "select * from product
		 where CategoryID='$categoryId' 
		 ORDER BY ProductName
         LIMIT $start,$display";
		$rl=mysql_query($sql, getConnect());
		$arr=array();
		if($rl!=null)
		{
		while ($cf = mysql_fetch_array($rl))
		{
		 	$arr[]=$cf;
		}
		}
		return $arr;
}
function countRowsByCategory($categoryId)
{
		  $sql= "select count(productID) from product where categoryID='$categoryId'";
		  $rl=mysql_query($sql, getConnect());
		  if($rl!=null)
		{

		   $rows = mysql_fetch_array($rl, MYSQLI_NUM);
			}
		   $record = $rows[0];
		   return $record;
}
function countRow()
{
		
		  $sql= "select count(productID) from product";
		  $rl=mysql_query($sql, getConnect());
		  if($rl!=null)
		{

		   $rows = mysql_fetch_array($rl, MYSQLI_NUM);
			}
		   $record = $rows[0];
		   return $record;
}
function getAllProduct( $start, $display)
{
 	$sql= "select * from product
		 ORDER BY ProductName
         LIMIT $start,$display";
		$rl=mysql_query($sql, getConnect());
		$arr=array();
		if($rl!=null)
		{
		while ($cf = mysql_fetch_array($rl))
		{
		 	$arr[]=$cf;
		}
		}
		return $arr;
}
function InsertComment($content, $name, $email, $productid, $date, $isvisable)
{
 	$sql="insert into commentproduct values (null,'$content','$name','$email','$productid','$date','isvisable')";
	$q="INSERT INTO commentproduct VALUES (NULL, 'cotent', 'aaaaa', 'wwwwwwwwwww', '1', '2012-11-28', '1');";
	$rl=mysql_query($sql, getConnect())
		or die (
		 mysql_error(getConnect()));
}
function getCommentHidden($prid)
{
 	$sql= "select * from commentproduct where isVisable=0 and ProductID='$prid'";
		$rl=mysql_query($sql, getConnect());
		$arr=array();
		while ($cmm = mysql_fetch_array($rl))
		{
		 	$arr[]=$cmm;
		}
		return $arr;
}
function getCommentShow($prid)
{
 	$sql= "select * from commentproduct where isVisable=1 and ProductID='$prid'";
		$rl=mysql_query($sql, getConnect());
		$arr=array();
		while ($cmm = mysql_fetch_array($rl))
		{
		 	$arr[]=$cmm;
		}
		return $arr;
}
function deleteComment($id)
{
  		$sql= "delete from commentproduct where CommentID='$id'";
		mysql_query($sql, getConnect()) or die (mysql_error(getConnect()));
}
function updateComment($id, $isVisable)
{
		$sql= "update commentproduct set isVisable=$isVisable where CommentID='$id'";
		mysql_query($sql, getConnect()) or die (mysql_error(getConnect()));
}

function updateViewCount($prid)
{
 	$sql= "update product set ViewCount=ViewCount+1 where ProductID='$prid'";
		mysql_query($sql, getConnect()) or die (mysql_error(getConnect()));
}
function getViewCount($prid)
{
    $sql= "select ViewCount from product where ProductID='$prid'";
		  $rl=mysql_query($sql, getConnect());
		  if($rl!=null)
		{

		   $rows = mysql_fetch_array($rl, MYSQLI_NUM);
			}
		   $record = $rows[0];
		   return $record;
}

?>